home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / dev / c / RConfig.lha / RConfig_v1.1 / rlib / crt0.a68 < prev    next >
Encoding:
Text File  |  1992-09-13  |  3.5 KB  |  131 lines

  1. ;:ts=8
  2. ;
  3. ; crt0.a68
  4. ; ~~~~~~~~
  5. ;   Copyright (C) 1986,1987 by Manx Software Systems, Inc.
  6. ;   Copyright (C) 1992 by Anthon Pang, Omni Communications Products.
  7. ;
  8.  
  9. ;    Initial startup routine for Aztec C.
  10.  
  11. ;    NOTE: code down to "start" must be placed at beginning of
  12. ;        all programs linked with Aztec Linker using small
  13. ;        code or small data.
  14.  
  15.     mc68881
  16.     entry   .begin
  17.     public  .begin
  18.  
  19. .begin
  20.  
  21.     ifd __RESSTART_MAIN
  22.         bsr     __geta4                 ;get A4 (the first time)
  23.     endc
  24.     ifnd __RESSTART_MAIN
  25.         bsr     _geta4                  ;get A4
  26.     endc
  27.  
  28.     lea     __H1_end,a1
  29.     lea     __H2_org,a2
  30.     cmp.l   a1,a2                   ;check if BSS and DATA together
  31.     bne     start                   ;no, don't have to clear
  32.     move.w  #((__H2_end-__H2_org)/4)-1,d1
  33.     bmi     start                   ;skip if no bss
  34.     move.l  #0,d2
  35.  
  36. loop
  37.     move.l  d2,(a1)+                ;clear out memory
  38.     dbra    d1,loop
  39.  
  40. start
  41.     move.l  sp,__savsp              ;save stack pointer
  42.     move.l  4,a6                    ;get Exec's library base pointer
  43.     move.l  a6,_SysBase             ;put where we can get it
  44.     movem.l d0/a0,-(sp)             ;save CLI command parameters
  45.  
  46.     btst.b  #4,$129(a6)             ;check for 68881 flag in AttnFlags
  47.     beq     1$                      ;skip if not
  48.     lea     2$,a5
  49.     jsr     -30(a6)                 ;do it in supervisor mode
  50.     bra     1$
  51.  
  52. 2$
  53.     clr.l   -(sp)
  54.     frestore (sp)+                  ;reset the ffp stuff
  55.     rte                             ;and return
  56.  
  57. 1$
  58.     lea     dos_name,a1             ;get name of dos library
  59.     jsr     -408(a6)                ;open the library any version
  60.     move.l  d0,_DOSBase             ;set it up
  61.     bne     3$                      ;skip if okay
  62.  
  63.     move.l  #$38007,d7              ;AG_OpenLib | AO_DOSLib
  64.     jsr     -108(a6)                ;Alert
  65.     bra     4$
  66.  
  67. 3$
  68.     jsr     __main                  ;call the startup stuff
  69.  
  70. 4$
  71.     add.w   #8,sp                   ;pop args
  72.     rts                             ;and return
  73.  
  74. dos_name:
  75.     dc.b    'dos.library',0
  76.  
  77.     ifd __RESSTART_MAIN
  78. __geta4:
  79.         bsr     _geta4
  80.  
  81.         movem.l d0-d1/a0-a1/a6,-(sp)    ;save temporary registers
  82.         move.l  #(__H2_end-__H1_org),d0 ;get size of data hunk
  83.         move.l  d0,-(sp)                ;save hunk size on stack
  84.  
  85.         move.l  $10000,d1               ;requirements (MEMF_CLEAR)
  86.         move.l  $0004,a6                ;LoadExecBase
  87.         jsr     -$00c6(a6)              ;jsr AllocMem
  88.         tst.l   d0
  89.  
  90.         bne     alloc_ok
  91.         addq.w  #4,sp                   ;AllocMem failed, clean up stack
  92.         bra     exitgeta4               ;and exit
  93.  
  94. alloc_ok:
  95.         lea     -32766(a4),a4
  96.  
  97.         move.l  d0,a0                   ;start of pseudo data hunk
  98.         move.w  #((__H2_end-__H1_org)/4)-1,d1
  99.         bmi     nocopy                  ;skip if empty data hunk
  100. copyloop:
  101.         move.l  (a4)+,(a0)+             ;copy from data hunk to pseudo data hunk
  102.         dbra    d1,copyloop
  103.  
  104. nocopy:
  105.         move.l  d0,a4                   ;get base of global data
  106.         lea     32766(a4),a4
  107.         move.l  (sp)+,__H_size#
  108.  
  109. exitgeta4:
  110.         movem.l (sp)+,d0-d1/a0-a1/a6    ;restore temporary registers
  111.         rts
  112.     endc
  113.  
  114.     public  _geta4
  115. _geta4:
  116.     far data
  117.     lea __H1_org+32766,a4
  118.     near data
  119.     rts
  120.  
  121.     public  __main,__H0_org
  122.  
  123.     dseg
  124.  
  125.     public  _SysBase,__savsp,_DOSBase
  126.     public  __H1_org,__H1_end,__H2_org,__H2_end
  127.  
  128.   ifd __RESSTART_MAIN
  129.     public __H_size
  130.   endc
  131.